<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css">   
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/themes/icon.css">
<!-- 引入Js -->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
<title>Insert title here</title>
</head>
<script type="text/javascript">
$(function(){
	var pager=$("#salarylist").datagrid('getPager');
	pager.pagination({
	pageList:[10,20,30],
	});
});
//显示工资添加数据框
function showaddsalary() {
	$("#addwin").window("open");
}
//清楚添加窗口中信息
function clearfrom(){
	
	$("#addform").form("clear")
}
//检验员工是否存在
$(function(){
	$(".wid").blur(function(){
		//1.1获取该文本框的值
		var wid=$(this).val();
		
	    $.ajax({
	    	type:"post",
	    	data:{"wid":wid},
	    	url:"validataworker",
	    	dataType:"text",
	    	success:function(data){
	    		if(data=="true"){
	    			$.messager.alert('提示','用户存在，可以添加');
	    		}else{
	    			$.messager.alert('提示','用户不存在，请重新输入','info',function(){
						$("#addform").form('clear');
					});
	    		}
	    	}
	    });
	});
	
});
//实现添加员工工资
function addsalary() {
	$("#addform").form('submit',{
		 success:function(){
			 $("#addwin").window("close"); //提交成功关闭添加员工窗口
			 //刷新员工页面
			 $.messager.alert("提示","添加成功",'info',function(){
 				$("#salarylist").datagrid('reload');
 			});   
		 }
	});
}
//为查询添加事件
function showselect() {
	//获取iuput框中的ID值
	var wid=$("#wid").val()
	//打开查询的框
	$("#findwin").window('open');
	$('#selectone').datagrid({   
	    url:'selectone',   
	    queryParams: {
	    	wid:wid,
		},
	    columns:[[   
	        {field:'wid',title:'员工ID',width:100},   
	        {field:'wname',title:'员工姓名',width:100},   
	        {field:'did',title:'部门ID',width:100},
	        {field:'month',title:'发放月份',width:100},   
	        {field:'salary',title:'工资总额',width:100},   
	        {field:'premium',title:'当月奖金',width:100},
	        {field:'deduct',title:'当月扣除',width:100} 
	    ]]   
	});  
}
//显示修改窗口
function showupdatesalary() {
	var data=$("#salarylist").datagrid('getSelections')
	 if(data.length!=1){
	    	$.messager.show({
	    		title:'警告',
	    		msg:'请选择你要修改的数据',
	    		timeout:1000,
	    		showType:'slide',
	    		style:{
	    			left:150,
	    			right:'',
	    			top:100
	    		}
	    	});
	   }else{
	      $("#updatewin").window("open");
	      var sids=[];
	      for (var i= 0; i < data.length; i++) {
			sids.push(data[i].sid);
		}
		$("#sid").attr("value",sids[0]);
	   }
}
//修改
function updatesalary() {
	var data=$("#salarylist").datagrid('getSelections')
	$("#updateform").form('submit',{
	 success:function(data){
	    	if(data=="1"){
	    		$("#updatewin").window("close");
	    		$.messager.alert("提示","修改成功",'info',function(){
	  			$("#salarylist").datagrid('reload');
	    		});
	    	}else{
	    		alert("修改失败");
	    	}
	    }
	});
}
//取消修改
function closewin() {
	$("#updatewin").window("close");
}

</script>
<body>
    <table id="salarylist" title="工资查询" class="easyui-datagrid"
            url="getsalary" 
            toolbar="#toolbar" pagination="true" fit="true" border="false"
            rownumbers="true" fitColumns="true" >
        <thead>
            <tr>
                <th field="ck" checkbox="true"></th>
                <th field="wid" width="25" hidden="ture">员工ID</th>
                <th field="wname" width="30" resizable="false">员工姓名</th>
                <th field="did" width="25" >部门ID</th>
                <th field="month" width="25">发放时间</th>
                <th field="salary" width="50">工资总数</th>
                <th field="premium" width="50">当月奖金</th>
                <th field="deduct" width="25" >当月扣除</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="showaddsalary()">增加</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="showupdatesalary()">修改</a>
                        请输入员工ID:<input type="text" id="wid" name="wid">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="showselect()">查询</a>
    </div>
    <!-- 添加工资数据 -->
       <div id="addwin" class="easyui-window" title="添加员工信息" closed="true" data-options="modal:true" style="width:300px;height:400px;">
    <form id="addform" method="post" action="addsalary" style="padding:10px 20px 10px 40px;">
     <p>员工ID: <input name="wid" class="wid" class="easyui-textbox" data-options="required:true" missingMessage="请输入员工ID"></p>
     <p>员工姓名: <input name="wname" class="wname" class="easyui-textbox" data-options="required:true" missingMessage="请输入员工姓名"></p>
     <p>部门ID: <input name="did" class="easyui-textbox"  data-options="required:true" missingMessage="请输入部门ID"></p>
     <p>发放月份: <input name="month" class="easyui-textbox" data-options="required:true" missingMessage="请输入月份"></p>
     <p>总工资: <input name="salary" class="easyui-textbox" data-options="required:true" missingMessage="请输入总工资"></p>
     <p>当月奖金: <input name="premium" class="easyui-textbox" data-options="required:true" missingMessage="请输入当月奖金"></p>
     <p>当月扣除: <input name="deduct" class="easyui-textbox" data-options="required:true" missingMessage="请输入当月扣除的金额"></p>
      <div style="padding:5px;text-align:center;">
    	<a href="#" class="easyui-linkbutton" icon="icon-ok" onclick="addsalary()">确认</a>
    	<a href="#" class="easyui-linkbutton" icon="icon-cancel"onclick="clearfrom()">清除</a>
      </div>
      </form>
     </div>
   <!-- 通过员工Id查询该员工的工资信息 -->
   <div class="easyui-window" closed="true" id="findwin" title="按条件查询员工所有工资信息"
		fit="true">
		<table id="selectone" class="easyui-datagrid" pagination="true" border="false" 
		rownumbers="true" fitColumns="true"fit="true"
			data-options="singleSelect:true,collapsible:true,method:'post'">
		</table>
  </div>
       <!-- 修改工资数据 -->
      <div id="updatewin" class="easyui-window" title="修改员工信息" closed="true" data-options="modal:true" style="width:300px;height:180px;">
    <form id="updateform" method="post" action="updatesalary" style="padding:10px 20px 10px 40px;">
     <input id="sid"  name="sid" class="easyui-validatebox" hidden="ture">
     <p>总工资: <input name="salary" class="easyui-textbox" data-options="required:true" missingMessage="请输入总工资"></p>
     <p>当月奖金: <input name="premium" class="easyui-textbox" data-options="required:true" missingMessage="请输入当月奖金"></p>
     <p>当月扣除: <input name="deduct" class="easyui-textbox" data-options="required:true" missingMessage="请输入当月扣除的金额"></p>
      <div style="padding:5px;text-align:center;">
    	<a href="#" class="easyui-linkbutton" icon="icon-ok" onclick="updatesalary()">确认</a>
    	<a href="#" class="easyui-linkbutton" icon="icon-cancel"onclick="closewin()">取消</a>
      </div>
      </form>
     </div>
</body>
</html>